﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtUserName.Text))
        {
            //alert
            return;
        }

        if (string.IsNullOrEmpty(txtPassWord.Text))
        {
            //alert
            return;
        }

        Permission permission = null;
        PermissionHelper helper = new PermissionHelper();
        if (txtPassWord.Text == "superadmin" && txtUserName.Text == "superadmin")
        {
            permission = helper.GetPermission(EUserRole.superadmin);
        }
        else
        {
            UserBLL bll = new UserBLL();
            InternalManagementSystem.DAO.Models.Staff user = bll.UserLogin(txtUserName.Text, txtPassWord.Text);
            if (user == null)
            {
                //wrong user
                Response.Write("<script> alert( '用户名或者密码错误！ ');location= 'login.aspx'</script> ");
                return;
            }
            else
            {
                permission = helper.GetPermission((EUserRole)user.RoleID);
                permission.UserID = user.UserID;
                permission.UserName = user.UserName;
            }
        }
          

        Session["Permission"] = permission;
        Response.Redirect("main.aspx");

    }
}